/*
	Copyright 2020-2023 Daniel T. Borelli <danieltborelli@gmail.com>

	This file is part of xrunit.

	xrunit is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	xrunit is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with xrunit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CONFIG_H_INCLUDE
#define CONFIG_H_INCLUDE
#define _XOPEN_SOURCE 500
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Hold_Browser.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Image.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/fl_ask.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Tabs.H>
#include <FL/Fl_Text_Editor.H>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <limits.h>
#include <string>
#include <ftw.h>
#include <dirent.h>
#include <ctime>

#include "debug.h"

#define VERSION @APP_VER@

#ifndef HOST_OS
#error "HOST_OS NOT DEFINED"
#endif

#ifndef SV
#error "SV NOT DEFINED"
#endif

#ifndef SV_RUN_DIR
#error "SV_RUN_DIR NOT DEFINED"
#endif

#ifndef SV_DIR
#error "SV_DIR NOT DEFINED"
#endif

#ifndef SYS_LOG_DIR
#error "SYS_LOG_DIR NOT DEFINED"
#endif

#ifdef DEBUG
#define TITLE "xrunit " VERSION "(debug) - " HOST_OS
#else
#define TITLE "xrunit " VERSION " - " HOST_OS
#endif

#define TITLE_SERVICE TITLE " - Services"
#define TITLE_SERVICE_NEW TITLE " - New service"
#define TITLE_SERVICE_EDIT TITLE " - Edit service"

#ifndef TIME_UPDATE
#define TIME_UPDATE 5
#endif


#ifndef ASK_SERVICES
// It doesn't have to be the exact name
#define ASK_SERVICES "tty,dbus,udev,elogind"
#endif

#define ASK_SERVICES_DELIM ","

#define NOTIFY_STR_SUMMARY TITLE "\n"
#define NOTIFY_STR_DOWN "Down service: %s"
#define NOTIFY_STR_UP  "Up service: %s"
#define NOTIFY_STR_RESTART "Restart service: %s"
#define NOTIFY_STR_DELETE "Delete service: %s"
#define NOTIFY_STR_KILL "Kill service: %s"
#define NOTIFY_STR_ALARM "Alarm service: %s"

// popen cmds
#define SV_LIST SV " status " SV_RUN_DIR"/*"

#define UNUSED __attribute__((unused))

#define SELECT_RESET 1
#define STR_SZ  200
#define BTN_W 80
#define BTN_H 25
#define BTN_X 10
#define BTN_Y 10
#define BTN_PAD 12

#ifndef FONT
#define FONT FL_HELVETICA
#endif

#ifndef FONT_SZ
#define FONT_SZ 11
#endif

#define LBL_COLOR 149
#define LBL_TAB_COLOR 151

enum {
/* Not move */

/* Fl_Button */
	RUN,
	DOWN,
	RESTART,
	KILL,
	QUIT,
	ADD,
	CLOSE,
	LOAD,
	UNLOAD,
	EDIT,
	NEW,
/* Fl_Button edit services */
	RUN_LOG,
	DOWN_LOG,
	RESTART_LOG,
	ALARM_LOG,
	KILL_LOG,
	DELETE_SRV,
	DISABLED_SRV,
	ENABLED_SRV,
	DELETE_LOG,
	DISABLED_LOG,
	ENABLED_LOG,
	SAVE,
	CANCEL,
	BTN_MAX,
/* Fl_Hold_Browser */
	ENABLE = 0,
	LIST,
	BROWSER_MAX,
/* Fl_Text_Buffer */
	TBUF_SERV = 0,
	TBUF_LOG,
	TBUF_LOG_CONF,
	TBUF_FINISH,
	TBUF_CONF,
	TBUF_CHECK,
	TBUF_MAX,
/* Fl_Text_Editor */
	TEDT_SERV = 0,
	TEDT_LOG,
	TEDT_LOG_CONF,
	TEDT_FINISH,
	TEDT_CONF,
	TEDT_CHECK,
	TEDT_MAX,
/* Fl_Box - time*/
	LBL_TIME_SERV = 0,
	LBL_TIME_LOG,
	LBL_TIME_LOG_CONF,
	LBL_TIME_FINISH,
	LBL_TIME_CONF,
	LBL_TIME_CHECK,
	LBL_TIME_MAX,
/* Fl_Group - label*/
	LBL_SERV = 0,
	LBL_LOG,
	LBL_LOG_RUN,
	LBL_LOG_CONF,
	LBL_LOG_EXTRA,
	LBL_FINISH,
	LBL_CONF,
	LBL_CHECK,
	LBL_MAX,
/* notify ids */
	NOTIFY_DOWN = 0,
	NOTIFY_UP,
	NOTIFY_RESTART,
	NOTIFY_DELETE,
	NOTIFY_KILL,
	NOTIFY_ALARM,
	NOTIFY_MAX,
};


struct NewEditData
{
	unsigned long hash[TBUF_MAX];
	Fl_Box* time[LBL_TIME_MAX];
	Fl_Group* label[LBL_MAX];
	Fl_Input* input;
	void* data;
	int id;
};
#endif
